From 1a6bad8e5bc822ce345903ab03b196694bad6c54 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 22 Apr 2016 17:49:12 -0500 Subject: [PATCH] cargo-install: prefer building artifacts in the system temporary directory and each cargo-install instance creates and uses its own build directory. This allows running several cargo-install instances in parallel. If we fail to create a temporary directory for whatever reason fallback to creating and using a target-install directory in the current directory. closes #2606 --- Cargo.toml | 2 +- src/cargo/lib.rs | 1 + src/cargo/ops/cargo_install.rs | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3c2649005..b522909ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ regex = "0.1" rustc-serialize = "0.3" semver = "0.2.2" tar = "0.4" +tempdir = "0.3" term = "0.4.4" time = "0.1" toml = "0.1" @@ -45,7 +46,6 @@ url = "0.2" winapi = "0.2" [dev-dependencies] -tempdir = "0.3" hamcrest = "0.1" bufstream = "0.1" filetime = "0.1" diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 2d5db07fa..ae67abc1b 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -19,6 +19,7 @@ extern crate regex; extern crate rustc_serialize; extern crate semver; extern crate tar; +extern crate tempdir; extern crate term; extern crate time; extern crate toml; diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index 916e35bd7..aab9c1e25 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -7,6 +7,7 @@ use std::io::prelude::*; use std::io::SeekFrom; use std::path::{Path, PathBuf}; +use tempdir::TempDir; use toml; use core::{SourceId, Source, Package, Registry, Dependency, PackageIdSpec}; @@ -79,13 +80,25 @@ pub fn install(root: Option<&str>, try!(check_overwrites(&dst, &pkg, &opts.filter, &list)); } + let mut td_opt = None; let target_dir = if source_id.is_path() { config.target_dir(&pkg) } else { - Filesystem::new(config.cwd().join("target-install")) + if let Ok(td) = TempDir::new("cargo-install") { + let p = td.path().to_owned(); + td_opt = Some(td); + Filesystem::new(p) + } else { + Filesystem::new(config.cwd().join("target-install")) + } }; config.set_target_dir(target_dir.clone()); let compile = try!(ops::compile_pkg(&pkg, Some(source), opts).chain_error(|| { + if let Some(td) = td_opt.take() { + // preserve the temporary directory, so the user can inspect it + td.into_path(); + } + human(format!("failed to compile `{}`, intermediate artifacts can be \ found at `{}`", pkg, target_dir.display())) })); -- 2.30.2